package com.geeklan.smart.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

import com.geeklan.smart.R;
import com.geeklan.smart.utils.DensityUtils;

public class DashedLineView extends View {
    private Paint paint;

    public DashedLineView(Context context) {
        super(context);
        init();
    }

    public DashedLineView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public DashedLineView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    public DashedLineView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init();
    }


    private void init() {
        paint = new Paint();
        paint.setColor(getContext().getColor(R.color.color_DEDEDE));
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(5);
        paint.setPathEffect(new DashPathEffect(new float[]{DensityUtils.dpToPx(getContext(),10), DensityUtils.dpToPx(getContext(),5)}, 0));  // 设置虚线
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        // 绘制水平虚线
        canvas.drawLine(getWidth() / 2, 0, getWidth() / 2, getHeight(), paint);  // 从顶部到底部
    }
}
